package com.itools.core.service.impl;

import com.itools.core.dto.businessType.FmsBusinessTypeDTO;
import com.itools.core.log.Logable;
import com.itools.core.mapper.FmsBusinessTypeMapper;
import com.itools.core.param.FmsUploadTokenParam;
import com.itools.core.result.FmsUploadTokenResult;
import com.itools.core.result.FmsBusinessTypeResult;
import com.itools.core.service.FmsBusinessTypeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: XUCHANG
 * @create: 2021-03-28 15:51
 */
@Service
public class FmsBusinessTypeServiceImpl implements FmsBusinessTypeService {
    @Autowired
    private FmsBusinessTypeMapper fmsBusinessTypeMapper;

    /**
     * 查询FsBusinessType列表
     *
     * @param businessType
     * @return
     */
    @Override
    @Cacheable(value = "fsBusinessTypes", key = "#businessType")
    @Logable
    public List<FmsBusinessTypeResult> queryFsBusinessTypeList(String businessType) {
        if (StringUtils.isBlank(businessType)) {
            return null;
        }
        FmsBusinessTypeDTO tmp = new FmsBusinessTypeDTO();
        tmp.setBusinessType(businessType);
        List<FmsBusinessTypeDTO> fssBusinessTypes = fmsBusinessTypeMapper.selectBySelective(tmp);
        List<FmsBusinessTypeResult> fmsBusinessTypeResults = new ArrayList<>();
        for (FmsBusinessTypeDTO fssBusinessType : fssBusinessTypes){
            FmsBusinessTypeResult fmsBusinessTypeResult = new FmsBusinessTypeResult();
            BeanUtils.copyProperties(fssBusinessType , fmsBusinessTypeResult);
            fmsBusinessTypeResults.add(fmsBusinessTypeResult);
        }
        return fmsBusinessTypeResults;
    }

    /**
     * 根据 uploadToken ，缓存FsBusinessType对象
     *
     * @param uploadToken
     * @return
     */
    @Override
    @Cacheable(value = "fsBusinessType", key = "#uploadToken")
    @Logable
    public FmsUploadTokenResult cacheFsUploadToken(String uploadToken, FmsUploadTokenParam fmsUploadTokenParam) {
        FmsUploadTokenResult result = new FmsUploadTokenResult();
        BeanUtils.copyProperties(fmsUploadTokenParam, result);
        return result;
    }

    /**
     * 根据 uploadToken ，获取FsBusinessType对象
     *
     * @param uploadToken
     * @return
     */
    @Override
    @Cacheable(value = "fsBusinessType", key = "#uploadToken")
    @Logable
    public FmsUploadTokenResult getFsBusinessTypeByUploadToken(String uploadToken) {
        return null;
    }

    @Override
    @CacheEvict(value = "fsBusinessType", key = "#uploadToken")
    @Logable
    public void deleteFsBusinessTypeByUploadToken(String uploadToken) {
    }
}
